package by.demchenko.sample.webapp.page.home;

import by.demchenko.sample.webapp.page.home.panel.*;
import by.demchenko.sample.webapp.page.home.share.HomePage;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.head.JavaScriptHeaderItem;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

public class BaseLayout extends WebPage {

    @Override
    protected void onInitialize() {
        super.onInitialize();
        add(new Label("headerTitle", getPageTitle()));
        add(new HeaderPanel("header"));
        add(new LanguagePanel("languagePanel"));

        AdvertPanel advert = new AdvertPanel("advert");
        advert.setOutputMarkupId(true);

        if (getClass() != HomePage.class) {
            advert.setVisible(false);
        };

        add(new SidebarPanel("sidebar"));

        add(advert);

        add(new FooterPanel("footer"));
    }

    @Override
    public void renderHead(IHeaderResponse response) {
        super.renderHead(response);
        response.render(JavaScriptHeaderItem.forReference(getApplication().getJavaScriptLibrarySettings().getJQueryReference()));
    }

    private IModel<String> getPageTitle() {
        return new Model<>(getClass().getSimpleName());
    }

}